package ipc;

public class iterationData{
	public int iternum;
	public long sizeofv;
	public long sizeofpi;
	public double itertime;
	public double be;
	public long sizeofq = 0;
	
	public String toInsert(int runid){
		StringBuffer sb = new StringBuffer();
		sb.append("INSERT INTO ITERSOLVE VALUES (");
		sb.append(runid);
		sb.append(", ");
		sb.append(iternum);
		sb.append(", ");
		sb.append(sizeofv);
		sb.append(", ");
		sb.append(sizeofpi);
		sb.append(", ");
		sb.append(itertime);
		sb.append(", ");
		sb.append(be);
		sb.append(", ");
		sb.append(sizeofq);
		sb.append(")");
		
		return sb.toString();
	}

	@Override
	public String toString() {
		return "iterationData [iternum=" + this.iternum + ", sizeofv="
				+ this.sizeofv + ", sizeofpi=" + this.sizeofpi + ", itertime="
				+ this.itertime + ", be=" + this.be + ", sizeofq="
				+ this.sizeofq + "]";
	}

	public iterationData(int iternum, long sizeofv, long sizeofpi, double itertime, double be, long sizeofq) {
		super();
		this.iternum = iternum;
		this.sizeofv = sizeofv;
		this.sizeofpi = sizeofpi;
		this.itertime = itertime;
		this.be = be;
		this.sizeofq = sizeofq;
	}
	
	public iterationData(iterationData other){
		this.iternum = other.iternum;
		this.sizeofv = other.sizeofv;
		this.sizeofpi = other.sizeofpi;
		this.itertime = other.itertime;
		this.be = other.be;
		this.sizeofq = other.sizeofq;
	}
	
	public void addIterationData(iterationData id){
		
		if( iternum != id.iternum ){
			System.err.println("wrong iter num... ");
			System.exit(1);
		}
		
		sizeofv += id.sizeofv;
		sizeofpi += id.sizeofpi;
		sizeofq += id.sizeofq;
		itertime += id.itertime;
		be += id.be;
		
	}
	
	public void finishUp(int nRuns){
		sizeofv /= nRuns;
		sizeofpi /= nRuns;
		sizeofq /= nRuns;
		itertime /= nRuns;
		be /= nRuns;
	}
	
}